import pandas as pd
import numpy as np

def cons__(c):
    def x(m):
        return pd.Series(c, index=range(0, m))
    return x

def rand__(a, b):
    def x(m):
        return pd.Series(np.random.rand(m) * a + b)
    return x

def rand_(m):
    return pd.Series(np.random.rand(m))

def range_(m):
    return pd.Series(range(0, m))

def choice__(c: list):
    def x(m):
        return pd.Series(np.random.choice(c, m))
    return x

def generate(m, columns):
    data = {key: value(m) for key, value in columns.items()}
    df = pd.DataFrame(data)
    return df



if __name__ == '__main__':
    columns = {
        "index": range_,
        "stype": cons__(2),
        "label": choice__([True, False]),
        "fe1": rand_,
        "fe2": rand_,
        "fe3": rand_,
        "fe4": rand_,
        "lbs_city_move_distance": rand__(10, 0),
        "tag_dataming_sex": choice__(['M', 'F']),
        "tag_dataming_sex_source": choice__(['precise', 'predict']),
        "dev_os": choice__(['web', 'ANDROID', 'H5', 'IOS', 'Windows_7', 'PC']),
        "dev_brand": choice__(['Apple', 'HUAWEI', 'vivo', 'OPPO', 'HONOR', 'Xiaomi', 'H5_CH_129PC', 'H5_CH_508PC', 'H5_CH_178PC', 'H5_CH_15547PC', 'H5_CH_15670PC', 'Redmi', 'H5_CH_15195PC', 'samsung', 'H5_CH_457PC', 'H5_CH_168PC', 'H5_CH_128PC', 'H5_CH_308PC', 'H5_CH_321PC', 'H5_CH_323PC', 'H5_CH_109PC', 'H5_CH_103PC', 'H5_CH_15394PC', 'H5_CH_102PC', 'H5_CH_566PC', 'H5_CH_15033PC', 'H5_CH_15538PC', 'H5_CH_612PC', 'xiaomi']),
    }
    apps = {'app_{}'.format(i) : choice__(['0', '1']) for i in range(20)}
    columns.update(apps)
    
    m = 50
    df = generate(m, columns)
    df['user_no'] = df['index'].apply(lambda x: "user_" + str(x))
    df.to_csv("/Users/tzp/Documents/private/cnm/Trial-7-Lan/PythonTest/notebooks/output/generate.csv",
               header=True, index=False)
    print(df)